<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5.4.2/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css"/>
<script type="text/javascript"
	src="<c:url value="/js/common.js"/>"></script>
</head>
<body>
<script type="text/javascript">

		function editCustomer(custId){
			$("#lwc-win-customer-add").dialog({href2:"editCustomerinfo/"+custId,title:"编辑客户信息"});
			alert(custId);
			
			$("#lwc_customer_insert").form('load', 'getCusinfoById/' + custId);
			$("#lwc-win-customer-add").dialog("open");	
		}

		function DetailsCustomer(custId){
	
		}

		function deleteCustomer(custId){
			
			$.messager.confirm('提示', '确定要删除吗？本数据视图下存在关联数据可能会被删除的！', function(v){
				if(v){
					
					$.getJSON("delOneCustomerInfo", {custId:custId}, function(data){
						if(data){
							$("#lwc_table").datagrid("load");
						}else{
							$.messager.alert("温馨提示","删除失败！本数据视图下存在关联数据！");
						}
					});
/* 					$('#lwc_table').datagrid({
						pageNumber : 1,
						url : 'get_all_csinfo_page'
					}); */
				}
			});
		}
		$(function() {
			
			//导出数据
			$("#lwc_informationFinancial_tb_export").linkbutton({onClick:function(){
				var code = $("#lwc_toCustomerclassify_cb").combobox('getValue');
				var value = $("#lwc_toCustomerclassify_mm_sb").searchbox('getValue');
				$("#lwc_informationFinancial_export_dlg").dialog({title: '数据导出'});
				$("#lwc_informationFinancial_export_dlg").dialog("open");
				var options = $('#lwc_table').datagrid('getPager').data("pagination").options;  
				var page = options.pageNumber;//当前页数
				var total = options.total;  
				var max = Math.ceil(total/options.pageSize);  
				var rows = options.pageSize;//每页的记录数（行数）  
				
				if(code=='全部数据'){
					$("#markcode").val('0');
				}else{
					$("#markcode").val(code);
				}
				$("#value").val(value);
				$("#page").val(page);
				$("#total").val(total);
				$("#rows").val(rows);
				//alert(page+" "+rows+" "+max);
			}});
			$('#lwc_toCustomerclassify_cb').combobox({onChange:function(n,o){
				
				//暂未解释
				$('#lwc_toCustomerclassify_mm_sb').searchbox('reset');
				var l = $('#lwc_toCustomerclassify_cb').combobox('getValue');
				if(l==1){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=1');
				}else if(l==2){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=2');
				}else if(l==3){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=3');	
				}else if(l==4){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=4');
				}else if(l==5){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=5');
				}else if(l==6){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=6');
				}else if(l==7){
					$('#lwc_table').datagrid('load','toQueryCustomer?markcode=7');
				}	
			}});
			
				//编辑
				$("#lwc-customer-add-ok").linkbutton({onClick:function(){
					alert("成功到达");
					var row = $("#lwc_table").datagrid("getSelected");
					
					$("#lwc_customer_insert").form({
						url: $('#lwc-win-customer-add').dialog('options').href2,
						method:"post",
						onSubmit:function(params){
							if(row != null){
								params.custId = row.custId;
							}
							return $(this).form('validate');
						},
						success:function(v){
							var obj = eval('(' + v + ')');
							if(obj.success){
								$('#lwc_table').datagrid('reload');
								$('#lwc_table_FinancialData').datagrid('reload');

							}else{
								$.messager.alert('提示', '操作失败, 原因：' + obj.message);
							}
							$("#lwc-win-customer-add").window("close");
						}
					}).submit();
				}}); 
				//添加
				$("#lwc_btn_customer_add").linkbutton({
					onClick : function() {
						
						$("#lwc-win-customer-add").dialog({href2:"addNewCustomerinfo",title:"新建客户信息"});
						
						$("#lwc_customer_insert").form("clear");
						
						$("#lwc-win-customer-add").dialog("open");
					
					}
				});

				//刷新
				$("#lwc_customer_list_all").linkbutton({
					onClick : function() {
						$('#lwc_table').datagrid({
							pageNumber : 1,
							url : 'get_all_csinfo_page'
						});
						$("lwc_table").datagrid("reload");
						$('#lwc_table_FinancialData').datagrid({
							pageNumber : 1,
							url : 'getALLfdata'
						});
					}
				});
				
				//批量删除
				$("#lwc_customer_list_deletemore").linkbutton({
					onClick:function(){
						var selRow = $("#lwc_table").datagrid('getSelections');	
						if(selRow.length == 0){
							$.messager.alert('温馨提示','请至少选择一行数据！');
							return false;
						}
						
						var ids=[];
						for (var i = 0; i < selRow.length; i++) {  
							var id=selRow[i].custId;
							ids.push(id);
					    } 
						$.messager.confirm("温馨提示","是否确认删除？",function(r){
							if(r){
								$.getJSON("delManyCustomerinfo",{"ids[]":ids},function(data){
									if(data){
										$.messager.alert("温馨提示","删除成功！");
										$("#lwc_table").datagrid("load");
									}else{
										$.messager.alert("温馨提示","删除失败！本数据视图下存在关联数据！");
										
									}
								})
							}
						}); 

					}
				});
 		//显示数据
		$("#lwc_table").datagrid({
			fit:true,
			toolbar:'#lwc-customer-function-tb',
			border:false,
			fitColumns:true,
			url:'get_all_csinfo_page',
			method:'get',
			singleSelect:false,
			pagination:true,
			columns:[[     
            {field:'xx',title:'',width:1,checkbox:true},
	        {field:'custId',title:'编号',width:1},    
	        {field:'custCname',title:'简称',width:1},  
	        {field:'custName',title:'客户名称',width:1},      
	        {field:'cjustKinds',title:'种类',width:1,formatter: function(value,row,index){ if(value==1){return '客户';}
         							 if(value==2){return '供应商';}
         							 if(value==3){return '合作伙伴';}
         							 if(value==4){return '媒体';}
         							 if(value==5){return '其他';}}},    
	        {field:'custCycle',title:'生命周期',width:1,formatter: function(value,row,index){if(value==1){return '潜在';}
         							else if(value==2){return '签约';}
         							else if(value==3){return '重复购买';}
         							else if(value==4){return '失效';}}},    
	        {field:'custAddress',title:'地址',width:1},    
	        {field:'custOperat',title:'拥有者',width:1},    
	        {field:'custPhone',title:'电话',width:1},    
	        {field:'custSrc',title:'来源',width:1},    
	        {field:'custCreatedata3',title:'创建日期',width:1.5,formatter: function(value,row,index){
	        	         							 if(value){
														var date=new Date(value);
														var y = date.getFullYear();
														var m = date.getMonth()+1;
														var d = date.getDate();
														return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
          								}}}, 
	        {field:'custUpdate',title:'更新日期',width:1.5,formatter: function(value,row,index){
	        	         							 if(value){
															var date=new Date(value);
															var y = date.getFullYear();
															var m = date.getMonth()+1;
															var d = date.getDate();
															return y+'年'+(m<10?('0'+m):m)+'月'+(d<10?('0'+d):d)+'日';
          								}}}, 
	        {field:'custRemarks',title:'备注',width:1},
	        {field:'bb',width:4,title:'操作', formatter:function(value, row, index){ 
	                var btn = '<a class="lwc-customer-edit" onclick="editCustomer('+row.custId+')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
	                var btn2 = '<a class="lwc-customer-delete" onclick="deleteCustomer('+row.custId+')" href="javascript:void(0)" class="easyui-linkbutton"></a>'; 
	                var btn3 = '<a class="lwc-customer-details" onclick="DetailsCustomer('+row.custId+')" href="javascript:void(0)" class="easyui-linkbutton"></a>'; 
	                return btn+btn2+btn3;  
	            }  
	        }  
	    ]],  
	    onLoadSuccess:function(data){  
	        $('.lwc-customer-edit').linkbutton({text:'编辑',plain:true,iconCls:'icon-edit'});  
	        $('.lwc-customer-delete').linkbutton({text:'删除',plain:true,iconCls:'icon-cut'}); 
	        $('.lwc-customer-details').linkbutton({text:'视图',plain:true}); 
	    }  
		});		
				
				
				
		
	})
				
		
</script>
<style>
.sep{
margin-top:15px;
margin-left:10px;
}
#lwc_customer_insert{

}
</style>


    <!-- 数据表格 -->
	<table id="lwc_table" class="easyui-datagrid">
	</table>	
	<!-- 功能按钮 -->
	<div id="lwc-customer-function-tb">
			<a id="lwc_btn_customer_add" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新建</a>
	        <a id="lwc_customer_list_all" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
	        <a id="lwc_customer_list_deletemore" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">批量删除</a>
	        <a id="lwc_informationFinancial_tb_export" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">导出数据</a>
    </div>
      <!-- 添加窗口 -->
    <div id="lwc-win-customer-add" class="easyui-dialog" style="width:800px; height: 500px; padding: 10px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
		<!--窗口布局  -->		
		<div class="easyui-layout" data-options="fit:true">
		  	<div data-options="region:'center'" style="padding:10px;">
		   		<form id="lwc_customer_insert" name="customerForm" method="post">
					<div class="sep"><input class="easyui-textbox" data-options="required:true,label:'公司',prompt:'公司名称',width:400, labelWidth:80" name="custCname"></div>
					<div class="sep"><input class="easyui-textbox" data-options="required:true,label:'客户',prompt:'客户名称',width:220, labelWidth:80" name="custName"></div>
					<div class="sep"><select class="easyui-combobox" data-options="required:true,panelHeight:'auto',label:'种类',
						width:250, labelWidth:80,valueField: 'label',
							textField: 'value',
							data: [{label: '1',value: '客户',selected:true},
								   {label: '2',value: '供应商'},
								   {label: '3',value: '合作伙伴'},
								   {label: '4',value: '媒体'},
								   {label: '5',value: '其他'}]" name="cjustKinds">

		
						</select></div>	
<!-- 					<div class="sep"><input class="easyui-textbox" data-options="required:true,label:'种类',width:220, labelWidth:80" name="cjustKinds"></div> -->
					<div class="sep"><input class="easyui-textbox" data-options="label:'电话',width:220, labelWidth:80" name="custPhone"></div>
					<div class="sep"><input id="lwc_form_source" class="easyui-textbox" name="custSrc" data-options="buttonText:'来源', label:'来源', labelWidth:'80', width: 300, 
						onClickButton:function(){
							getSource(function(row){
								$('#lwc_form_source').textbox('setValue', row.csContent);
							});
						}">
					</div> 				
					<div class="sep"><select class="easyui-combobox" data-options="panelHeight:'auto',required:true,label:'拥有者',
						width:250, labelWidth:80" name="custOperat">
						<option value="赵军">赵军</option>
						<option value="刘立军">立军</option>
						<option value="陶禁">陶禁</option>
						<option value="刘伟成">刘伟成</option>
						<option value="肖鹏">肖鹏</option>
						<option value="王卫宁">王卫宁</option>
						</select></div>					
						<div class="sep"><input class="easyui-textbox" data-options="label:'地址',prompt:'地址',width:400, labelWidth:80" name="custAddress"></div>
					 <div class="sep"><input id="coStartTime" class="easyui-datebox" data-options="label:'创建日期',width:300, labelWidth:80" name="custCreatedata3" ></div>
					<div class="sep"><input class="easyui-textbox" data-options="multiline:true,label:'备注',width:400, labelWidth:80" name="custRemarks"></div>
				</form>
		  	</div>
		  	
		    <div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0; text-align: center;">
		     	<a id="lwc-customer-add-ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true">保存</a>
		     	<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" href="javascript:void(0)" onclick="javascript:$('#lwc-win-customer-add').window('close');">取消</a>
	 	   </div>
		</div>	
			
    </div>
    
</body>
</html>